package com.panda.controller.auth;


import com.panda.annotation.SystemLog;
import com.panda.entity.vo.RegisterVo;
import com.panda.entity.vo.UserVo;
import com.panda.service.LoginService;
import com.panda.service.UserService;
import com.panda.utils.RespondResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "登陆接口")
@RestController
public class LoginController {

    private final UserService userService;

    private final LoginService loginService;

    @Autowired
    public LoginController(UserService userService, LoginService loginService) {
        this.userService = userService;
        this.loginService = loginService;
    }

    @ApiOperation("注册")
    @PostMapping("register")
    public RespondResult register(@Validated @RequestBody RegisterVo registerVo) {
        return userService.register(registerVo);
    }

    @ApiOperation("登陆")
    @PostMapping("login")
    public RespondResult login(@Validated @RequestBody UserVo userVo) {
        return loginService.login(userVo);
    }

    @ApiOperation("登出")
    @PostMapping("logout")
    public RespondResult logout() {
        return loginService.logout();
    }
}
